package leetcode.hot100;

import java.util.ArrayList;
import java.util.Arrays;

public class Solution48 {

    public static void main(String[] args) {
        int[][] matrix = {{5,1,9,11},{2,4,8,10},{13,3,6,7},{15,14,12,16}};
        new Solution48().rotate(matrix);
        System.out.println();
    }

    public void rotate(int[][] matrix) {
        int row = matrix.length-1;
        int col = matrix[0].length-1;
        //先上下翻，再沿着对角线翻
        for (int i = 0; i <=row/2; i++) {
            int[] tmp = matrix[i];
            matrix[i] = matrix[row-i];
            matrix[row-i] = tmp;
        }
        //对角线翻
        for (int i = 0; i <= row; i++) {
            for (int j = i+1; j <= col; j++) {
                int tmp = matrix[i][j];
                matrix[i][j] = matrix[j][i];
                matrix[j][i] = tmp;
            }
        }
    }
}
